package com.abacus.pay.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class PayVoucher {
	private final static SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd");
	private Long id;
	private Long voucherId;
	private Double payMoney;
	private Calendar calendar;

	public PayVoucher() {
		super();
	}

	public PayVoucher(Long voucherId) {
		super();
		this.voucherId = voucherId;
	}

	public PayVoucher(Long voucherId, Calendar calendar) {
		super();
		this.voucherId = voucherId;
		this.calendar = calendar;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getVoucherId() {
		return voucherId;
	}

	public void setVoucherId(Long voucherId) {
		this.voucherId = voucherId;
	}

	public Double getPayMoney() {
		return payMoney;
	}

	public void setPayMoney(Double payMoney) {
		this.payMoney = payMoney;
	}

	public Calendar getCalendar() {
		return calendar;
	}

	public void setCalendar(Calendar calendar) {
		this.calendar = calendar;
	}

	public void setCalendar(String calendar) {
		this.calendar = toCalendar(calendar);
	}

	private Calendar toCalendar(String calendar) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = FORMAT.parse(calendar);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		return c;
	}

	public String getDate() {
		return null == calendar ? null : FORMAT.format(calendar.getTime());
	}
}
